package middleware

import (
	"gbox-one-machine/models"
	"gbox-one-machine/node"
	"github.com/gin-gonic/gin"
	"net/http"
)

// MasterMiddleware for gin
func MasterMiddleware() func(c *gin.Context) {
	return func(c *gin.Context) {

		if node.GetNodeRole() != node.RoleMaster {
			defer c.Abort()

			c.JSON(http.StatusInternalServerError, &models.HTTPResp{
				ReturnCode:   models.RespCodeError,
				ErrorMessage: "Server is not master, can not request this method",
			})
			return

		}

		c.Next()
	}
}

